import React, { Component } from 'react'
import {NavBar,Form,Button,TextArea,Toast,Space} from "antd-mobile";
import {withRouter} from "react-router";
import {PRIVATE_ROUTE} from "../../../../route.constants";
import axios from "../../../../http";
import Qs from 'qs'
class ReportEdit extends Component {
    constructor(props) {

        super(props);
        this.state={
            id:this.props.location.state.id,
            reportDate:this.props.location.state.reportDate,
            start:this.props.location.state.start,
            end:this.props.location.state.end,
            type:this.props.location.state.type,
            workContentTitle:this.props.location.state.workContentTitle,
            nextWorkPlanTitle:this.props.location.state.nextWorkPlanTitle,
            workContent:this.props.location.state.workContent,
            nextWorkPlan:this.props.location.state.nextWorkPlan,
            memo:this.props.location.state.memo
          }
    }
    deleteById=()=> {
        axios.post('api/oa/work/report/deleteById', Qs.stringify({
            id:this.state.id
        }),{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
            .then((response)=>{
                let  data=response.data;
                if(data.status==1){
                    this.showSuccessMessage(data.message)
                }else{
                    this.showErrorMessage(data.message);
                }

            })
            .catch(function (error) {
                this.showErrorMessage(error);
            });

    }
    update=() =>{
        let entity={id:this.state.id,workContent:this.state.workContent,nextWorkPlan:this.state.nextWorkPlan,memo:this.state.memo};
        axios.post('api/oa/work/report/update', Qs.stringify({
            requestJson:JSON.stringify(entity)
        }),{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
            .then((response)=>{
                let  data=response.data;
                if(data.status==1){
                    this.setState({modalEditVisible:false})
                    this.showSuccessMessage(data.message)
                }else{
                    this.showErrorMessage(data.message);
                }

            })
            .catch(function (error) {
                this.showErrorMessage(error);
            });

    }
    showSuccessMessage (systemMessage){
 
        Toast.show({
            content:  systemMessage,
            afterClose: () => {
                console.log('success')
              },
            
          })
    };
    showErrorMessage (systemMessage){
 
        Toast.show({
            content:  systemMessage,
            afterClose: () => {
                console.log('fail')
              },
            
          })
    };
    render() {
        return (
            <div>
                 <NavBar onBack={()=>{this.props.history.push({ pathname: "/main/"+PRIVATE_ROUTE.APP_OA_WORK_REPORT_MINE})}} >添加</NavBar>
                 <Form
                    footer={
                        <space style={{ 'gap': '30px' }}>
                        <Button block type='submit' color='danger' onClick={this.deleteById}>
                            删除
                        </Button>
                    
                        <Button block type='submit' color='primary' onClick={this.update}>
                            提交
                        </Button>
                        </space>
                    }
                >
                <Form.Item
                    label='日期'
                >
                    <label>{this.state.reportDate}</label>
                </Form.Item>
                <Form.Item
                    label='工作时间'
                >
                    <label>09:00:00-18:00:00</label>
                </Form.Item>
                <Form.Item
                    label={this.state.workContentTitle+"工作内容"}
                >
                    <TextArea
                        placeholder="工作内容"
                        value={this.state.workContent}
                        onChange={(value)=>{this.setState({workContent:value})}}
                        autoSize={{ minRows: 3, maxRows: 5 }}
                        showCount
                        maxLength={300}
                    />
                </Form.Item>
                <Form.Item
                    label={this.state.nextWorkPlanTitle+'工作计划'}
                >
                    <TextArea
                        placeholder="工作计划"
                        value={this.state.nextWorkPlan}
                        onChange={(value)=>{this.setState({nextWorkPlan:value})}}
                        autoSize={{ minRows: 3, maxRows: 5 }}
                        showCount
                        maxLength={300}
                    />
                </Form.Item>
                <Form.Item
                    label='备注'
                >
                    <TextArea
                        placeholder="备注"
                        value={this.state.memo}
                        onChange={(value)=>{this.setState({memo:value})}}
                        autoSize={{ minRows: 3, maxRows: 5 }}
                        showCount
                        maxLength={300}
                    />
                </Form.Item>


                </Form>
            </div>
        )
    }
}
export default  withRouter(ReportEdit)